import { createRequire } from 'node:module'
import commonjs from '@rollup/plugin-commonjs'
import ckeditor5 from '@ckeditor/vite-plugin-ckeditor5'
import tailwindcss from '@tailwindcss/vite'

const require = createRequire(import.meta.url)

export default defineNuxtConfig({
  compatibilityDate: '2025-03-16',
  devtools: { enabled: true },
  experimental: {
    asyncContext: true,
  },
  sourcemap: true,
  srcDir: './src',
  css: ['~/assets/css/tailwind.css'],
  modules: ['reka-ui/nuxt'],
  imports: {
    autoImport: true,
    dirs: ['api', 'utils/fns', 'utils/fetch', 'utils/nuxt', 'uses'],
  },

  build: {
    analyze: {
      'template': 'treemap',
      'projectRoot': '/<rootDir>',
      'filename': '/<rootDir>/.nuxt/analyze/{name}.html',
    },
  },

  app: {
    pageTransition: { name: 'page', mode: 'out-in' },
  },

  nitro: {
    compressPublicAssets: true, // 开启静态资源gzip压缩
    routeRules: {
      '/**': {
        cors: true,
        headers: {
          'Cross-Origin-Embedder-Policy': 'credentialless',
          'Cross-Origin-Resource-Policy': 'cross-origin',
          'Access-Control-Allow-Origin': '*',
          'Access-Control-Allow-Methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
          'Access-Control-Allow-Headers': 'Content-Type,Authorization',

          /*'Access-Control-Allow-Origin': '*',
          'Cross-Origin-Embedder-Policy': 'credentialless',
          'Cross-Origin-Opener-Policy': 'same-origin',
          'Cross-Origin-Resource-Policy': 'same-origin',*/
        },
      },
    },
  },


  devServer: {
    // host: 'www.vxin.com', // 自定义域名
  },

  vite:{
    server: {
      allowedHosts: [
        'vxin.com',
        'www.vxin.com',
        'www-dev.vxin.com',
      ],
    },
    plugins: [
      commonjs(),
      ckeditor5( { theme: require.resolve( '@ckeditor/ckeditor5-theme-lark' ) } ),
      tailwindcss(),
    ],
  },
})
